<!doctype html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>图书后台管理系统</title>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="stylesheet" href="../Xadmin/css/font.css">
    <link rel="stylesheet" href="../Xadmin/css/xadmin.css">
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <!-- <link rel="stylesheet" href="./css/theme5.css"> -->
    <script src="../layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../Xadmin/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <script>
        var is_remember = false;
    </script>
</head>
<body>

<div class="layui-form-item">
    <label class="layui-form-label">手机号：</label>
    <div class="layui-input-block">
        <input class="layui-input" name="phone" id="phone" autocomplete="off" style="width: 30rem;" />
    </div>
</div>
<div class="layui-form-item">
    <label class="layui-form-label">密码：</label>
    <div class="layui-input-block">
        <input class="layui-input" name="pwd" id="pwd" autocomplete="off" style="width: 30rem;"/>
    </div>
</div>

<button class="layui-btn" style="margin-left:20rem" onclick="addUser()">添加</button>
</body>
<script>
    layui.use('layer', function () {
        console.log('layer导入成功！')
    })
    function addUser(){
        var myreg=/^1[358][0123456789]\d{8}$/;
        if(!myreg.test($("#phone").val())){
            layer.alert("请输入正确的手机号！", {icon: 5})
        }else if (($("#pwd").val())==''){
            layer.alert("请输入密码！", {icon: 5})
        }else{
            $.ajax({
                url:"http://127.0.0.1:8081/User/User",
                method:"post",
                data:{
                    phone:$("#phone").val(),
                    upwd:$("#pwd").val(),
                },
                success: function (res) {
                    var object = JSON.parse(res)
                    if (object.code === '0') {
                        layer.alert("添加成功")
                    } else {
                        layer.alert("添加失败")
                    }
                    reload()
                }
            })
        }

    }
</script>
</html>